package com.leyou.mapper;

import com.leyou.pojo.Brand;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import tk.mybatis.mapper.additional.idlist.SelectByIdListMapper;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

public interface BrandMapper extends Mapper<Brand>, SelectByIdListMapper<Brand, Long> {

    /**
     * 新增品牌和商品类目中间表数据
     *
     * @param cid 商品类目id
     * @param bid 品牌id
     * @return
     */
    @Insert("INSERT INTO tb_category_brand (category_id, brand_id) VALUES (#{cid},#{bid})")
    int insertCategoryBrand(@Param("cid") Long cid, @Param("bid") Long bid);

    /**
     * 根据品牌id删除品牌和商品类目中间表数据
     *
     * @param bid
     * @return
     */
    @Delete("delete from tb_category_brand where brand_id = #{bid}")
    int deleteCategoryBrand(@Param("bid") Long bid);

    /**
     * 根据商品分类查询品牌
     *
     * @param cid
     * @return
     */
    @Select("SELECT a.* FROM tb_brand a left join tb_category_brand b on a.id = b.brand_id WHERE b.category_id = #{cid}")
    List<Brand> queryBrandsByCid(@Param("cid") Long cid);
}
